package com.summer.ChengXuYuanMianShiJingDian;

import com.summer.ListNode;

public class Q2_2 {
    public int kthToLast(ListNode head, int k) {
        int count = 0;
        ListNode listNode = head;
        while(listNode!=null){
            count++;
            listNode = listNode.next;
        }
        int target = count - k + 1;
        for(int i = 1;i<=count;i++){

            if(i==target){
                return head.val;
            }
            head = head.next;
        }
        return 0;
    }
}
